<?php
    class WebController extends Controller
    {
        public $customer;
        
        public $cats;

        // global data
        public $siteNameIsH1 = true; // set h1 in header is H1 or H2

        public $latestPosts = array(); // 3 post latest
//        public $popularPosts = array(); // 10 hot & vip latest
        public $noIndexFollow = false;
        
        public function init(){

            parent::init();
            Yii::app()->clientScript->registerCssFile(Yii::app()->clientScript->getCoreScriptUrl().'/jui/css/base/jquery-ui.css');
            $this->customer = Yii::app()->user->customer;

            $this->latestPosts = Post::model()->findAllByAttributes(array('status' => 'ENABLE'), array(
                'order' => 'created DESC',
                'limit' => 5,
            ));
//            
//            
//            $popularCriteria = new CDbCriteria();
//            $popularCriteria->addInCondition('type', array('HOT', 'VIP'));
//            $popularCriteria->addCondition('status = "PUBLISH"');
//            $popularCriteria->order = 'id DESC';
//            $popularCriteria->limit = 10;
//            $this->popularPosts = Post::model()->findAll($popularCriteria);
        }

        public function render1($view, $data = null, $return = false, $options = null)
        {
            $output = parent::render($view, $data, true);

            $compactor = Yii::app()->contentCompactor;
            if($compactor == null)
                throw new CHttpException(500, Yii::t('messages', 'Missing component ContentCompactor in configuration.'));

            // remove comment on client    
            $output = preg_replace('#^\s*//.+$#m', '', $output);
            $output = $compactor->compact($output, $options);

            if($return)
                return $output;
            else
                echo $output;
        }

}